package ab.mes.controller;


import ab.mes.entity.ProcessFirstInspection;
import ab.mes.service.ProcessFirstInspectionService;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/processFirstInspectionController")
public class ProcessFirstInspectionController {
    @Autowired
    ProcessFirstInspectionService processFirstInspectionService;

    //根据工序名查询工序的所有首检项
    @PostMapping("/selectByProcess")
    public Result selectByProcess(String process){
        Result result=new Result();
        try {
            result = processFirstInspectionService.selectByProcess(process);
        }catch (Exception e){
            result.setErrorMessage("查询首检项失败！");
            e.printStackTrace();
        }
        return result;
    }
    //根据检查项名查询工序的所有首检项
    @PostMapping("/selectByName")
    public Result selectByName(String name){
        Result result=new Result();
        try {
            result = processFirstInspectionService.selectByName(name);
        }catch (Exception e){
            result.setErrorMessage("查询首检项失败！");
            e.printStackTrace();
        }
        return result;
    }
    //为某个工序插入首检项
    @PostMapping("/insertInspection")
    public Result insertInspection(@RequestBody ProcessFirstInspection processFirstInspection){
        Result result=new Result();
        try {
            result = processFirstInspectionService.insertInspection(processFirstInspection);
        }catch (Exception e){
            result.setErrorMessage("添加首检项失败！");
            e.printStackTrace();
        }
        return result;
    }
}
